SWEP.Author 		= "Tezzanator"
SWEP.Instructions 	= "Point and shoot"
SWEP.Contact 		= ""
SWEP.Purpose 		= "Creates a barrier..."
 
SWEP.AdminSpawnable = false
SWEP.Spawnable 		= false
 
SWEP.ViewModelFOV 	= 64
SWEP.ViewModel 		= "models/weapons/v_pistol.mdl" 
SWEP.WorldModel 	= "models/weapons/w_pistol.mdl"
 
SWEP.HoldType = "Pistol"
SWEP.ReloadSound = "weapons/pistol/pistol_reload1.wav"

SWEP.base = "weapon_base" 

SWEP.Primary.ClipSize = -1;
SWEP.Primary.DefaultClip = -1;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = "none";

SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = "none";



-- aware of gamemode specifics, such as stats.
-- LEts load them now
function SWEP:Equip( NewOwner )

end

function SWEP:PrimaryAttack() 
	local owner = self.Owner
	
	if(owner:GetMoney() < INV_BARRIERCOST)then
		if(SERVER)then
			SendErrorMessageToPlayerChat(owner, "You can't afford a barrier!")
		end
		return
	else
		local barriers = ents.FindByClass("inv_barrier") 
		if(#barriers >= INV_MAXBARRIERS)then
			if(SERVER)then
				SendErrorMessageToPlayerChat(owner, "There are too many barriers!")
			end
			return
		end
		owner:DeductMoney(INV_BARRIERCOST)
	end
	
	local tr = self.Owner:GetEyeTrace()
	if ( !tr.HitWorld ) then return end
 
	local effectdata = EffectData()
	effectdata:SetOrigin( tr.HitPos )
	effectdata:SetNormal( tr.HitNormal )
	effectdata:SetMagnitude( 8 )
	effectdata:SetScale( 1 )
	effectdata:SetRadius( 16 )
	util.Effect( "Sparks", effectdata )

	self.BaseClass.ShootEffects( self )
 
	if ( !SERVER ) then return end
 
	local ent = ents.Create( "inv_barrier" )
	local ang = tr.HitNormal:Angle()
	local angp = self.Owner:GetAimVector():Angle() 
		
	ent:SetPos( tr.HitPos  )
	ent:SetAngles( Angle(ang.p + 90, angp.y, ang.r ) )
	ent:Spawn()
	
	-- Physics is never enabled on this...
	local phys = ent:GetPhysicsObject()
	if phys:IsValid() then
		phys:EnableMotion(false)
	end
end 
